home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -serious- / programming / other / pmdev / c / demos / pulldownmenu.c < prev    next >
C/C++ Source or Header  |  2000-02-28  |  5KB  |  182 lines

  1. //
  2. // $VER: PullDownMenu.c 2.1 (05.09.98)
  3. //
  4. // Popup Menu example program
  5. //
  6. // ©1996-1997 Henrik Isaksson
  7. // All Rights Reserved.
  8. //
  9. // Run and click the mouse in the window!
  10. //
  11.  
  12. #include <intuition/intuition.h>
  13. #include <exec/memory.h>
  14.  
  15. #include <proto/intuition.h>
  16. #include <proto/exec.h>
  17.  
  18. #include <clib/alib_protos.h>
  19.  
  20. #include <string.h>
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23.  
  24. #include <libraries/pm.h>
  25. #include <proto/pm.h>
  26.  
  27. struct IntuitionBase    *IntuitionBase;
  28. struct GfxBase        *GfxBase;
  29. struct PopupMenuBase    *PopupMenuBase;
  30.  
  31. struct Window *w;    // This window is only needed to find out when and where the menu should appear.
  32.             // The font in this window's rastport will be used for the menu.
  33.  
  34. ULONG __saveds __asm MenuHandlerFunc(register __a0 struct Hook *hook,
  35.                      register __a2 APTR object,
  36.                      register __a1 APTR msg)
  37. {
  38.     struct PopupMenu *pm=(struct PopupMenu *)object;
  39.  
  40.     printf("---\n");
  41.     printf("Title:      \"%s\"\n", pm->Title);
  42.     printf("UserData: %lx\n", pm->UserData);
  43.     printf("ID:      %lx\n", pm->ID);
  44.  
  45.     // This is one (the fastest) way of finding out if the item is checked or not:
  46.     // 0x40000000 = CHECKIT
  47.     // 0x80000000 = CHECKED
  48.     if(pm->Flags&0x40000000)
  49.         printf("Checked?  %s\n", pm->Flags&0x80000000?"Yes":"No");
  50.  
  51.     if((int)pm->UserData==5) *((BOOL *)hook->h_Data)=FALSE;
  52. }
  53.  
  54. struct PopupMenu *MakeTestMenu(void);
  55.  
  56. void main()
  57. {
  58.     BOOL r=TRUE;
  59.     struct IntuiMessage *im,imsg;
  60.     struct PopupMenu *p;
  61.     struct Hook MenuHandler;
  62.  
  63.     MenuHandler.h_Entry=(HOOKFUNC)MenuHandlerFunc;
  64.     MenuHandler.h_Data=&r;
  65.  
  66.     PopupMenuBase=(struct PopupMenuBase *)OpenLibrary(POPUPMENU_NAME,POPUPMENU_VERSION);            // Open the library
  67.     if(PopupMenuBase) {
  68.         IntuitionBase=(struct IntuitionBase *)PopupMenuBase->pmb_IntuitionBase;    // We let popupmenu.library open the libraries we need
  69.         GfxBase=(struct GfxBase *)PopupMenuBase->pmb_GfxBase;            // They remain valid until the library is closed!
  70.  
  71.         p=MakeTestMenu(); // Declared at the end of this file.
  72.  
  73.         if(p) {
  74.             w=OpenWindowTags(NULL,    WA_IDCMP,    IDCMP_CLOSEWINDOW|IDCMP_MOUSEBUTTONS|IDCMP_VANILLAKEY,    // Open a little window
  75.                     WA_RMBTrap,    TRUE,
  76.                     WA_DragBar,    TRUE,
  77.                     WA_Width,    150,
  78.                     WA_Height,    100,
  79.                     WA_Left,    0,
  80.                     WA_Top,        100,
  81.                     WA_Title,    "PullDown Menus",
  82.                     WA_CloseGadget,    TRUE,
  83.                     TAG_DONE);
  84.             if(w) {
  85.                 while(r) {
  86.                     WaitPort(w->UserPort);                        // Wait for a message
  87.                     while((im=(struct IntuiMessage *)GetMsg(w->UserPort))) {    // Get the message
  88.                         CopyMem(im,&imsg,sizeof(struct IntuiMessage));        // Copy the contents of it
  89.                         ReplyMsg((struct Message *)im);                // Reply the message
  90.  
  91.                         PM_FilterIMsg(w, p, &imsg,                // Send the message to pmlib
  92.                             PM_AutoPullDown,    TRUE,            // We want the menu to open automatically
  93.                             PM_MenuHandler,        &MenuHandler,        // Our menuhandler function
  94.                             TAG_DONE);
  95.  
  96.                         if(imsg.Class==IDCMP_CLOSEWINDOW) r=FALSE;        // See if the user wants to quit
  97.                     }
  98.                 }
  99.                 CloseWindow(w);
  100.             } else printf("Window error!\n");
  101.             PM_FreePopupMenu(p);
  102.         } else printf("Menu error!\n");
  103.         CloseLibrary((struct Library *)PopupMenuBase);
  104.     }
  105. }
  106.  
  107. struct PopupMenu *MakeTestMenu()
  108. {
  109.     struct PopupMenu *p;
  110.  
  111.     p=PM_MakeMenu(
  112.         PMItem("Workbench"),
  113.             PMSimpleSub,
  114.                 PMCheckItem("Backdrop?", 1),        PM_CommKey,    "B",    End,
  115.                 PMItem("Execute Command..."),        PM_CommKey,    "E",    End,
  116.                 PMItem("Redraw All"),    End,
  117.                 PMItem("Update All"),    End,
  118.                 PMItem("Last Message"),    End,
  119.                 PMItem("About..."),    PM_CommKey,    "?",    End,
  120.                 PMItem("Quit"),        PM_UserData,    5,    PM_CommKey,    "Q",    End,
  121.             End,
  122.             PM_UserData,    5986,
  123.             PM_NoSelect,    FALSE,
  124.         End,
  125.         PMItem("Window"),
  126.             PMSimpleSub,
  127.                 PMItem("New Drawer"),        PM_CommKey,    "N",    PM_Disabled,    TRUE,    End,
  128.                 PMItem("Open Parent"),                    PM_Disabled,    TRUE,    End,
  129.                 PMItem("Close"),        PM_CommKey,    "K",    PM_Disabled,    TRUE,    End,
  130.                 PMItem("Update"),                    PM_Disabled,    TRUE,    End,
  131.                 PMItem("Select Contents"),    PM_CommKey,    "A",                End,
  132.                 PMItem("Clean Up"),        PM_CommKey,    ".",                End,
  133.                 PMItem("Snapshot"),
  134.                     PMSimpleSub,
  135.                         PMItem("Window"),    End,
  136.                         PMItem("All"),        End,
  137.                     End,
  138.                 End,
  139.                 PMItem("Show"),
  140.                     PMSimpleSub,
  141.                         PMCheckItem("Only Icons", 2),    PM_Exclude,    PM_ExLst(3, 0),    PM_Checked,    TRUE,    End,
  142.                         PMCheckItem("All Files", 3),    PM_Exclude,    PM_ExLst(2, 0),    End,
  143.                     End,
  144.                     PM_Disabled,    TRUE,
  145.                     //PM_BuiltInIcon,    PMIMG_SHOW,
  146.                 End,
  147.                 PMItem("View By"),
  148.                     PMSimpleSub,
  149.                         PMCheckItem("Icon", 4),        PM_Exclude,    PM_ExLst(5, 6, 7, 0),    PM_Checked,    TRUE,    End,
  150.                         PMCheckItem("Name", 5),        PM_Exclude,    PM_ExLst(4, 6, 7, 0),    End,
  151.                         PMCheckItem("Date", 6),        PM_Exclude,    PM_ExLst(4, 5, 7, 0),    End,
  152.                         PMCheckItem("Size", 7),        PM_Exclude,    PM_ExLst(4, 5, 6, 0),    End,
  153.                     End,
  154.                     PM_Disabled,    FALSE,
  155.                 End,
  156.             End,
  157.         End,
  158.         PMItem("Icons"),
  159.             PMSimpleSub,
  160.                 PMItem("Open"),            PM_CommKey,    "O",    End,
  161.                 PMItem("Copy"),            PM_CommKey,    "C",    End,
  162.                 PMItem("Rename..."),        PM_CommKey,    "R",    End,
  163.                 PMItem("Information..."),    PM_CommKey,    "I",    End,
  164.                 PMItem("Snapshot"),        PM_CommKey,    "S",    End,
  165.                 PMItem("UnSnapshot"),        PM_CommKey,    "U",    End,
  166.                 PMItem("Leave Out"),        PM_CommKey,    "L",    End,
  167.                 PMItem("Put Away"),        PM_CommKey,    "P",    End,
  168.                 PMBar,                            End,
  169.                 PMItem("Delete..."),        PM_Disabled,    TRUE,    End,
  170.                 PMItem("FormatDisk..."),                End,
  171.                 PMItem("Empty Trash"),        PM_Disabled,    TRUE,    End,
  172.             End,
  173.         End,
  174.         PMItem("Tools"),
  175.             PMSimpleSub,
  176.                 PMItem("ResetWB"),    End,
  177.             End,
  178.         End,
  179.     End;
  180.  
  181.     return p;
  182. }